/* To minimize memory usage, we label the elements in each row of the triangle
 * from right to left. That is, in the i-th row, the right-most element has 
 * index 1, ..., and the left-most element has index i. We also conveniently
 * initialize all elements to zero.
 *
 * Below is an example of such labeling. The numbers in parentheses are the
 * indices of the elements.
 *                 7(1)
 *             3(2)    8(1)
 *         8(3)    1(2)    0(1)
 *     2(4)    7(3)    4(2)    4(1)
 * 4(5)    5(4)    2(3)    6(2)    5(1)
 */

#include <stdio.h>

#define MAX_N 350
#define Max(a, b) ((a) > (b)? (a) : (b))

int main()
{
    int N, i, j, m;
    int sum[MAX_N+1] = { 0 };
    scanf("%d", &N);
    scanf("%d", &sum[1]);
    for (i = 2; i <= N; i++)
    {
        for (j = i; j >= 1; j--)
        {
            int x;
            scanf("%d", &x);
            sum[j] = x + Max(sum[j], sum[j-1]);
        }
    }
    m = 0;
    for (j = 1; j <= N; j++)
        m = Max(m, sum[j]);
    printf("%d\n", m);
    return 0;
}